package org.eclipseuseradmin.internal.ui.expressions;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipseuseradmin.ui.IRoleRootDescriptor;

public class IRoleRootDescriptorPropertyTester extends PropertyTester {

	private final static String ATT_ID = "id";
	
	private final static String ATT_NAME = "name";

	private final static String ATT_FILTER = "filter";
	
	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {

		if (!(receiver instanceof IRoleRootDescriptor)) {
			return false;
		}

		IRoleRootDescriptor roleRootDescriptor = (IRoleRootDescriptor) receiver;
		if (property.equals(ATT_NAME)) {
			return toString(expectedValue).equalsIgnoreCase(roleRootDescriptor.getName());
		} else if (property.equals(ATT_ID)) {
			return toString(expectedValue).equalsIgnoreCase(roleRootDescriptor.getId());
		}else if (property.equals(ATT_FILTER)) {
			return toString(expectedValue).equalsIgnoreCase(roleRootDescriptor.getFilter());
		}
		return false;
	}
	
	private String toString(Object object) {

		if (object == null) {
			return "";
		}
		return object.toString();
	}

}
